function changeToGroup(){
	changeTitle("groups");
	getGroups();
}

function getGroups(){
	arry=[];
	$.post("getGroupByUserId",function(data){
		if (data == "" || data == null) {
			return;
		}
		var groups = new Array();
		groups = getModelArray(data);
		$("#groups .STYLE7").remove();
		for (var i = 0; i < groups.length; i++) {
			var group = groups[i];
			var tr = $('<tr align="center" id="'+group.groupId+'"></tr>');
			if (i % 2 == 0) {
				tr.css("background-color", "#FFFFFF");
			}
			else {
				tr.css("background-color", "#EBF4FD");
			}
			tr.addClass("STYLE7");
			tr.mouseover(function(){
				oldColor = $(this).css("background-color");
				$(this).css("background-color", "#EEEEEE");
			});
			tr.mouseout(function(){
				$(this).css("background-color", oldColor);
			});
			tr.html('<td height="20"><input onclick="oncheck(this)" id="group' + group.groupId + '" type="checkbox"/></td><td ><a href="javascript:getContactByGroupId('+group.groupId+')">'+group.groupName+'</a></td><td>&nbsp;'+group.describe+'&nbsp;</td><td>'+group.count+'</td><td><a href="javascript:modGroup('+group.groupId+')">详细/编辑</a></td><td><img title="删除" src="images/delAll.gif" onclick="JavaScript:delGroupByGroupId('+group.groupId+')" style="cursor:pointer" class="cursor1"/></td>').appendTo($("#groups"));
		}
	},"text");
}
function getContactByGroupId(groupId){
	arry=[];
	$.post("getContactByGroupId",{"groupId":groupId},function(data){
		if(data==""){
			show_Message("该群组内没有任何联系人!","red");
			return;
		}
		var contacts = new Array();
		contacts = getModelArray(data);
		changeTitle("contacts");
		$("#contacts .STYLE7").remove();
		for(var i=0;i<contacts.length;i++){
			var contact = contacts[i];
			var tr = $('<tr align="center" id='+contact.contactId+'></tr>');
			if(i%2==0){
				tr.css("background-color","#FFFFFF");					
			}else{
				tr.css("background-color","#EBF4FD");	
			}
			tr.addClass("STYLE7");
			tr.mouseover(function(){
				oldColor = $(this).css("background-color");
				$(this).css("background-color","#EEEEEE");
			});
			tr.mouseout(function(){
				$(this).css("background-color",oldColor);
			});
			tr.html('<td height="20"><input onclick="oncheck(this)" id="contact'+contact.contactId+'" type="checkbox"/></td><td>'+contact.fullName+'</td><td>'+contact.sex+'</td><td>&nbsp;'+contact.mobilePhone+'&nbsp;</td><td>&nbsp;'+contact.email+'&nbsp;</td><td>&nbsp;'+contact.QQ+'&nbsp;</td><td>&nbsp;'+contact.MSN+'&nbsp;</td><td><a href="javascript:getContactByGroupId('+contact.groupId+')">'+contact.groupName+'</a></td><td><a href="javascript:modContact('+contact.contactId+')">详细/编辑</a></td><td><img style="cursor:pointer" onclick="JavaScript:oneForwardTo('+contact.contactId+')" class="cursor1" title="转移到" src="images/forward.gif"/></td><td><img title="删除" onclick="JavaScript:delContactById('+contact.contactId+')" style="cursor:pointer" class="cursor1"  src="images/delAll.gif" /></td>').appendTo($("#contacts"));
		}
	},"text");
}

function delGroup(){
	if(arry.length>0){
		$.post("delGroupByGroupId",{"list":arry.toString()},function(data){
			if(date=="data"){
				getGroups();
				show_Message("批量删除群组完成","green");
			}else{
				show_Message('"我的联系人"为系统默认群组,不能删除!',"red");
			}
		},"text")
	}else{
		show_Message("请选择您要删除的群组","red");
	}
}

function delGroupByGroupId(groupId){
		$.post("delGroupByGroupId",{"list":groupId},function(data){
			if(data=="true"){
				getGroups();
				show_Message("删除群组完成","green");
			}else{
				show_Message('"我的联系人"为系统默认群组,不能删除!',"red");
			}
		},"text");
}
function modGroup(groupId) {
	tmpId=groupId;
	tb_show("修改联系人信息","addGroup.html?TB_iframe=true&height=250&width=685&modal=false",null);
}